package cn.edu.nuc.ssm.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.ssm.controller.page.PageControl;
import cn.edu.nuc.ssm.controller.page.Pager;
import cn.edu.nuc.ssm.controller.page.Pc;
import cn.edu.nuc.ssm.dao.FilmMapper;
import cn.edu.nuc.ssm.domain.Film;
import cn.edu.nuc.ssm.service.interfaces.FilmService;
@Service
public class FilmServiceImpl implements FilmService {
	
	@Autowired
	private FilmMapper filmMapper;
	
    /**
     * 发布一部电影
     */
	@Override
	public int releaseFilm(Film film) {
		int result = filmMapper.insert(film);
		if(result == 1){
			System.out.println("添加电影成功！");
		}else{
			System.out.println("添加电影失败！");
		}
		return result;
	}
    /**
     * 分页查询电影信息
     */
	@Override
	public Pager<Film> pageList(String filmname, int current) {
		PageControl pc = new PageControl();
		Integer currindex = 1;
		if(current != 0){
			currindex = current;
		}
		pc.setCurrentindex(currindex);
		int count = filmMapper.count("%"+filmname+"%");
		pc.setRscount(count);
		pc = Pc.dealpage(pc);
		List<Film> film = filmMapper.selectFilm("%"+filmname+"%",(pc.getCurrentindex()-1)*pc.getPagesize(),
				pc.getCurrentindex()*pc.getPagesize());
		Pager<Film> pager = new Pager<Film>();
		pager.setList(film);
		pager.setPagectrl(pc);
		return pager;
	}
    /**
     * 通过主键查询单个电影信息。
     */
	@Override
	public Film selectByFilmid(Integer filmid) {
		return filmMapper.selectByPrimaryKey(filmid);
	}
    /**
     * (有选择进行)更新电影信息
     */
	@Override
	public int updateByPrimaryKey(Film film) {
		System.out.println("sssss"+filmMapper.updateByPrimaryKeySelective(film));
		return filmMapper.updateByPrimaryKeySelective(film);
	}
    /**
     * 删除单个电影信息。
     */
	@Override
	public int deleteByPrimaryKey(Integer filmid) {
		return filmMapper.deleteByPrimaryKey(filmid);
	}
	
	//活得全部的电影的信息
	@Override
	public List<Film> select() {
		return filmMapper.select();
	}
	//获得全部的3个模块信息。
	@Override
	public List<List<Film>> select2() {
		// TODO Auto-generated method stub
		List<List<Film>> listall = new ArrayList<List<Film>>();
		List<Film> list1 =  filmMapper.selectByHot();
		List<Film> list2 =  filmMapper.selectByNew();
		listall.add(list1);
		listall.add(list2);
		return listall;
	}
	
	//没有使用。
	@Override
	public List<Film> selectByHot() {
		// TODO Auto-generated method stub
		return null;
	}

}
